package com.grandbroad.eim.adapter;

import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.grandbroad.eim.R;
import com.grandbroad.eim.entry.VipBean;

import java.util.ArrayList;
import java.util.List;

/**
 * vipcard的适配器
 */
public class VipCardAdpter extends BaseAdapter
{

    private List<VipBean> vipBeanList = new ArrayList<>();

    public VipCardAdpter()
    {
        VipBean vipBean_1 = new VipBean();
        vipBean_1.setId(1);
        vipBean_1.setNow_price(240);
        vipBean_1.setOld_price(360);
        vipBean_1.setTime("1年");
        vipBeanList.add(vipBean_1);
        VipBean vipBean_2 = new VipBean();
        vipBean_2.setId(2);
        vipBean_2.setTime("6个月");
        vipBean_2.setOld_price(180);
        vipBean_2.setNow_price(120);
        vipBeanList.add(vipBean_2);
        VipBean vipBean_3 = new VipBean();
        vipBean_3.setId(3);
        vipBean_3.setOld_price(90);
        vipBean_3.setNow_price(60);
        vipBean_3.setTime("3个月");
        vipBeanList.add(vipBean_3);
        VipBean vipBean_4 = new VipBean();
        vipBean_4.setId(4);
        vipBean_4.setTime("1个月");
        vipBean_4.setOld_price(30);
        vipBean_4.setNow_price(20);
        vipBeanList.add(vipBean_4);
    }
    @Override
    public int getCount()
    {
        return 4;
    }
    @Override
    public Object getItem(int position)
    {
        return vipBeanList.get(position);
    }
    public void setSelectPostion(int postion)
    {
        boolean isselect = false;
        //循环遍历去除所有选中
        for (VipBean bean:vipBeanList)
        {
            bean.setSelect(false);
        }
        vipBeanList.get(postion).setSelect(true);
        //更新列表
        notifyDataSetChanged();
    }
    @Override
    public long getItemId(int position)
    {
        return 0;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.vip_card,parent,false);
        TextView tv_old = v.findViewById(R.id.tv_old_price);
        TextView tv_now = v.findViewById(R.id.tv_now_price);
        TextView tv_time = v.findViewById(R.id.tv_time);
        LinearLayout li_card = v.findViewById(R.id.li_card);
        //中划线
        tv_old.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
        VipBean bean = vipBeanList.get(position);
        li_card.setEnabled(bean.isSelect());
        tv_old.setText("¥"+bean.getOld_price());
        tv_now.setText("¥"+bean.getNow_price());
        tv_time.setText(bean.getTime());
        return v;
    }
}
